<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IEmployeeAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/interfaces/IConnectionAccessDao.php';
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/ConnectionFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];

  	class MySqlEmployeeAccessDao implements IEmployeeAccessDao {
   		/**
		 * Constructor of the employee dao
		 */
	 	public function __construct () {}
	   
     	/**
		 * Creates an employee
		 */
		public function createEmployee($employee) {
			$pkIdNumber = $employee -> getPkIdNumber();
			$firstName = $employee -> getFirstName();
			$secondName = $employee -> getSecondName();
			$firstLastName = $employee -> getFirstLastName();
			$secondLastName = $employee -> getSecondLastName();
			$emailAddress = $employee -> getEmailAddress();
			
			$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
			$conn = $connection -> openConnection();
			 
			$query = "INSERT INTO EMPLOYEE 
					  VALUES ($pkIdNumber, '$firstName', '$secondName', '$firstLastName',
					  	'$secondLastName', '$emailAddress')";
						
			$sentence = mysql_query($query, $conn);
			 
			if ($sentence)
				return true;
			
			return false;			 
		}
		 
	 public function changeEmployee($pk_id_number, $first_name, $second_name, $first_last_name, 
			$second_last_name, $email_address) {
	   
	    $connection = ConnectionFactory::getMySqlConnectionAccessDao();
		$conn=$connection->openConnection();
		$conn = mysql_connect("localhost", "root", "");
		mysql_select_db("sager", $conn);	
		 
		$query = "UPDATE EMPLOYEE SET $pk_id_number=$pk_id_number, $first_name='$first_name', $second_name='$second_name', $first_last_name='$first_last_name',$second_last_name='$second_last_name', $email_address='$email_address'";
	 
	 
	 
	    $sentence=mysql_query($query,$conn);
	       if ($sentence){
			    return true;
			   }
		  return false;
	 
	 }
	 
	 /**
		 * Selects all Employees
		 */
		public function selectEmployees() {
			$connection = ConnectionFactory :: getMySqlConnectionAccessDao();
			$conn = $connection -> openConnection();
			
					$GLOBALS['debug']->log('Inicio funcion select employees  dao');
					$query = "SELECT pk_id_number,first_name,second_name,first_last_name,
					          second_last_name,email_address
							  FROM EMPLOYEE";
			
			$GLOBALS['debug'] -> log($query, "Query");
				
			
			$sentence = mysql_query($query, $conn);
				
			$conn = $connection -> closeConnection($conn);
				$GLOBALS['debug']->log('Funcion DAO EMPLEADO');
						$GLOBALS['debug']->log($query,'fin funcion select employees');
			return $sentence;
		 }
		 
  
  }


?>